//
// Created by xili on 2024/8/14 21:23.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int minSetSize(vector<int> &arr) {
        int n = arr.size();
        map<int, int> m;
        for (auto &item: arr) {
            m[item]++;
        }
        vector<int> cnts;
        for (auto &item: m) {
            cnts.push_back(item.second);
        }
        sort(cnts.begin(), cnts.end(), greater<int>());
        int ans = 0;
        int sum = 0;
        for (auto item: cnts) {
            if (sum + item < n / 2) {
                sum += item;
                ans++;
            } else {
                break;
            }
        }
        return ans;
    }
};